package com.twu.biblioteca;

import java.util.ArrayList;

public class PopulateMovies {

    private ArrayList<PopulateMovies> movieShelf;
    private String movieName;
    private int year;
    private String director;
    private String rating;

    private static int initializingIndex = 0;

    public ArrayList<PopulateMovies> getMovieShelf() {
        return movieShelf;
    }

    public void addMoviesToRepository() {

        this.movieShelf = new ArrayList<PopulateMovies>();
        PopulateMovies movie1 = this.insert("12 Angry Men", 1957, "Sidney Lumet", "9.8");
        this.movieShelf.add(movie1);
        PopulateMovies movie2 = this.insert("Citizen Kane", 1941, "Orson Welles", "9.5");
        this.movieShelf.add(movie2);
        PopulateMovies movie3 = this.insert("Life Is Beautiful", 1997, "Roberto Benigni", "9.4");
        this.movieShelf.add(movie3);
        PopulateMovies movie4 = this.insert("Gone With The Wind", 1939, "Victor Fleming", "9.4");
        this.movieShelf.add(movie4);
        PopulateMovies movie5 = this.insert("Schindler's List", 1993, "Stephen Spielberg", "9.3");
        this.movieShelf.add(movie5);
        PopulateMovies movie6 = this.insert("Gandhi", 1982, "Richard Attenborough", "9.2");
        this.movieShelf.add(movie6);
        PopulateMovies movie7 = this.insert("Down By Law", 1986, "Jim Jarmusch", "9.0");
        this.movieShelf.add(movie7);
        PopulateMovies movie8 = this.insert("Double Indemnity", 1944, "Billy Wilder", "8.9");
        this.movieShelf.add(movie8);
        PopulateMovies movie9 = this.insert("The Big sleep", 1946, "Howard Hawks", "8.8");
        this.movieShelf.add(movie9);
        PopulateMovies movie10 = this.insert("I Confess", 1953, "Alfred Hitchcock", "8.7");
        this.movieShelf.add(movie10);
        PopulateMovies movie11 = this.insert("Shadow Of a Doubt", 1943, "Alfred Hitchcock", "8.6");
        this.movieShelf.add(movie11);
        PopulateMovies movie12 = this.insert("The Bridge On The River Kwai", 1957, "David Lean", "8.4");
        this.movieShelf.add(movie12);
        PopulateMovies movie13 = this.insert("Fast & Furious 6", 2013, "Justin Lin", "N/A");
        this.movieShelf.add(movie13);
        PopulateMovies movie14 = this.insert("Hangover 3", 2013, "Todd Philips", "N/A");
        this.movieShelf.add(movie14);
        PopulateMovies movie15 = this.insert("Aashiqui 2", 2013, "Mohit Suri", "N/A");
        this.movieShelf.add(movie15);

        this.viewAllMovies();

    }

    public PopulateMovies insert(String movieName, int year, String director, String rating) {
        PopulateMovies sample_movie = new PopulateMovies();
        sample_movie.movieName = movieName;
        sample_movie.year = year;
        sample_movie.director = director;
        sample_movie.rating = rating;
        return sample_movie;
    }

    public void viewAllMovies() {

        PopulateMovies movieToBeViewed;
        System.out.println(String.format("%28S | %S | %20S | %S", "MOVIE", "YEAR", "DIRECTOR", "RATING"));
        while (!(this.getMovieShelf().get(initializingIndex).rating.equals("N/A"))) {
            if (initializingIndex < this.getMovieShelf().size())
            {movieToBeViewed = this.getMovieShelf().get(initializingIndex);
             System.out.println(String.format("%28S | %d | %20S | %S", movieToBeViewed.movieName, movieToBeViewed.year, movieToBeViewed.director, movieToBeViewed.rating));
            }
            ++initializingIndex ;
        }
        System.out.println(String.format("\n%28S | %S | %20S | %S", "MOVIE", "YEAR", "DIRECTOR", "RATING"));

        while (initializingIndex < this.getMovieShelf().size()){
            movieToBeViewed = this.getMovieShelf().get(initializingIndex);
            System.out.println(String.format("%28S | %d | %20S | %S", movieToBeViewed.movieName, movieToBeViewed.year, movieToBeViewed.director, movieToBeViewed.rating));
            ++initializingIndex ;
        }
    }
}
